package com.yl.chainStore.control.sick

import com.yl.chainStore.control.BaseCtrl
import com.yl.chainStore.entity.sick.SickConsultRecordDetail
import com.yl.chainStore.pojo.vo.sick.SickConsultRecordsDetailSelectVo
import com.yl.chainStore.services.IConsultRecordService
import com.yl.common.ErrorCode
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnError
import com.yl.common.control.returnSuccess
import org.springframework.transaction.annotation.Transactional
import org.springframework.transaction.interceptor.TransactionAspectSupport
import org.springframework.web.bind.annotation.*
import java.util.*


/**
 * 咨询记录相页面
 * @author dy
 */
@RestController
@RequestMapping("sick/record")
open class SicktRecordController(
  private val iConsultRecordService: IConsultRecordService,

  ) : BaseCtrl() {

  /**
   * 新增咨询记录
   */
  @PostMapping("createSickRecord")
  @Transactional(rollbackFor = [Exception::class])
//  @PermsCode("sick:record:add")
  open fun createSickRecord(@RequestBody record: SickConsultRecordDetail): ResponseBody {
    iConsultRecordService.saveRecord(record)
    return returnSuccess()
  }


  /**
   *	删除咨询记录
   */
  @PostMapping("deleteSickRecord/{id}")
  @Transactional(rollbackFor = [Exception::class])
  open fun deleteSickRecord(@PathVariable id: Long): ResponseBody {
    val delDetail = iConsultRecordService.delRecordById(id)
    if (delDetail.bodyIsError()) {
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
    }
    return delDetail
  }

  /**
   * 通过咨询id获取咨询内容
   */
  @GetMapping("getRecordByRecordId/{id}")
  @Transactional
  open fun getRecordByRecordId(@PathVariable id: Long): ResponseBody {
    val detail = iConsultRecordService.getRecord(id)
    return returnSuccess(detail)
  }

  /**
   * 修改咨询记录
   */
  @PostMapping("updateSickRecord")
  @Transactional(rollbackFor = [Exception::class])
//  @PermsCode("sick:record:update")
  open fun updateSickRecord(@RequestBody sickConsultRecordDetail: SickConsultRecordDetail): ResponseBody {
    val updateMedicalHistory = iConsultRecordService.updateRecord(sickConsultRecordDetail)
    if (updateMedicalHistory.bodyIsError()) {
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
    }
    return updateMedicalHistory
  }


  /**
   * 某客户咨询记录的明细列表ØØØ
   */
  @PostMapping("getCustomerConsultRecordDetailList")
//  @PermsCode("sick:record:detail:list")
  @Transactional
  open fun getCustomerConsultRecordDetailList(@RequestBody vo: SickConsultRecordsDetailSelectVo): ResponseBody {
    if (vo.customerId == null) {
      return returnError(ErrorCode.PARAM_EMPTY)
    }
    val customerConsultRecordsDetailList = iConsultRecordService.getCustomerConsultRecordsDetailList(vo)
    return returnSuccess(customerConsultRecordsDetailList)
  }


}
